package com.hxd.mall.module.usercenter.invitataion

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.viewpager.widget.PagerAdapter
import com.hxd.mall.R
import com.hxd.mall.utils.open.load

/**
 * Create by yinzhengwei on 2019-11-05
 * @Function
 */
class CardAdapter(var context: Activity, var invitation: Invitation) : PagerAdapter() {

    override fun isViewFromObject(view: View, `object`: Any) = view == `object`

    override fun getCount() = invitation.bgImgList.size

    override fun instantiateItem(container: ViewGroup, position: Int): View {
        val view = LayoutInflater.from(context).inflate(R.layout.item_card_layout, null)
//        val imageView = view.findViewById<ImageView>(R.id.iv_icon)
        val tv_code = view.findViewById<TextView>(R.id.tv_code)
//        val tv__bg_code = view.findViewById<TextView>(R.id.tv__bg_code)
        val view_pagerview_pagerview_pager = view.findViewById<RelativeLayout>(R.id.view_pagerview_pagerview_pager)

//        imageView.load(invitation.bgImgList[position])
//        tv__bg_code.load(invitation.bgImgList[position])
        view_pagerview_pagerview_pager.load(invitation.bgImgList[position])
        tv_code.text = invitation.invitationCode

        container.addView(view)
        return view
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View?)
    }
}